"use strict";
cc._RF.push(module, 'e31dekxeU1ETZPA5U8Y0TCd', 'AssemblyItem');
// scripts/AssemblyItem.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
}), o.AssemblyItem = o.Assembly_Type = void 0;
var r = t("CarConstant"),
    s = t("HallCarWheelControl"),
    l = t("HallCarWeaponControl"),
    c = t("HallCarToolsControl"),
    d = t("GlobalUserData"),
    h = t("Util"),
    p = t("Global"),
    u = t("HallCarTotalView"),
    f = t("Hint"),
    m = cc._decorator,
    _ = m.ccclass,
    y = m.property;
o.Assembly_Type = {
  Default: 0,
  Assembly: 1,
  Hall: 2,
  Attribute: 3,
  GameMatch: 4,
  GameOver: 5,
  Sell: 6,
  SuperCar: 7
};

var g = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.node_item = null, e.carWheelFrame0_control = null, e.carWheelFrame1_control = null, e.carWeaponFrame0_control = null, e.carToolsFrame0_control = null, e.node_null = null, e.node_car = null, e.node_wheel = null, e.node_weapon = null, e.node_tools = null, e.node_arrCar = new Array(), e.node_arrWheel = new Array(), e.node_arrWeapon = new Array(), e.node_arrTools = new Array(), e.node_star = null, e.node_arrStar = new Array(5), e.frame_starLeveArr = [], e.frame_buffIcon = [], e.spr_explain = null, e.label_explain = null, e.node_arrowhead = null, e.node_light = null, e.carSpriteFrame1 = [], e.carSpriteFrame2 = [], e.isPitchOnStart = !1, e.isPitchOnEnd = !1, e._assemblyView = null, e.nIndex = 0, e.isTouchEnable = !1, e.isHall = !1, e.nAssemblyType = o.Assembly_Type.Default, e.itemDataUid = 0, e.itemData = null, e.isBodyMove = null, e.isTouchMove = !1, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStartCallback, this, !0), this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoveCallback, this, !0), this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEndCallback, this, !0), this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCacelCallback, this, !0);
  }, e.prototype.initItem = function () {
    this.node_null.active = !1, this.node_car.active = !1, this.node_wheel.active = !1, this.node_weapon.active = !1, this.node_tools.active = !1, this.node_light.active = !1, this.isPitchOnEnd = !1;

    for (var t = 0; t < this.node_arrWheel.length; t++) {
      this.node_arrWheel[t].active = !1;
    }

    for (t = 0; t < this.node_arrCar.length; t++) {
      this.node_arrCar[t].active = !1;
    }

    for (t = 0; t < this.node_arrWeapon.length; t++) {
      this.node_arrWeapon[t].active = !1;
    }

    for (t = 0; t < this.node_arrTools.length; t++) {
      this.node_arrTools[t].active = !1;
    }
  }, e.prototype.setItembodyState = function () {
    this.isBodyMove = !0;
  }, e.prototype.updateItem = function (t, e, i, n, a, s, l, c) {
    var u = this;
    if (this.initItem(), this.onActive(!0), this._assemblyView = t, this.nIndex = i, this.isTouchEnable = a, this.nAssemblyType = s, this.label_explain.node.parent.active = !1, this.isHall = s == o.Assembly_Type.Hall || s == o.Assembly_Type.SuperCar, !n) return s == o.Assembly_Type.Hall && (this.node_null.active = !0), this.node.getChildByName("icon_video").active = !1, void (this.node.getChildByName("icon_video_tt").active = !1);
    this.itemDataUid = n.uid, this.itemData = n, null != this.itemData.video && this.itemData.video ? h.Util.is_tt() ? this.node.getChildByName("icon_video_tt").active = !0 : this.node.getChildByName("icon_video").active = !0 : (this.node.getChildByName("icon_video").active = !1, this.node.getChildByName("icon_video_tt").active = !1), this.nAssemblyType == o.Assembly_Type.Assembly ? (this.node_arrowhead.active = !0, this.setArrow()) : this.node_arrowhead.active = !1, this.setStarQuality(this.frame_starLeveArr[0]), this.showStar(n.star), s == o.Assembly_Type.SuperCar && (this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStartCallback, this, !0), this.node.off(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoveCallback, this, !0), this.node.off(cc.Node.EventType.TOUCH_END, this.onTouchEndCallback, this, !0), this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCacelCallback, this, !0)), this.node_star.active = a && !this.isHall || s == o.Assembly_Type.Attribute;
    var f = this.isHall ? r.colliderTag.Hall : r.colliderTag.assembly;

    switch (n.type) {
      case r.Basics_Items_Type.body:
        this.node_car.active = !0;
        var m = r.getBodyData(n.id).index;
        this.node_arrCar[m].active = !0, this.node_arrCar[m].getChildByName("body").active = !0;

        var _ = this.node_arrCar[m].getChildByName("body");

        _.getComponent(cc.Sprite).spriteFrame = e ? this.carSpriteFrame1[m] : this.carSpriteFrame2[m], null != n.quality && n.quality == p.Quality.epic ? (h.Util.setBodyParts(_, d["default"].pbf_partsArr[m]), this.setStarQuality(this.frame_starLeveArr[1]), this.nAssemblyType == o.Assembly_Type.Assembly && (this.label_explain.node.parent.active = !0, this.setBuffInfo(n.buff))) : _.removeAllChildren(), this.showEquipFrame(s, n.id, m, f.body), this.carWheelFrame0_control.setOpacity(l ? 0 : 255), this.carWheelFrame1_control.setOpacity(c ? 0 : 255), this.isHall && this._assemblyView && this._assemblyView.updateAttributeItem(n);
        break;

      case r.Basics_Items_Type.wheel:
        this.node_wheel.active = !0;
        var y = r.getWheelData(n.id).index;
        this.node_arrWheel[y].active = !0, this.node_arrWheel[y].getComponent(cc.CircleCollider) && (this.node_arrWheel[y].getComponent(cc.CircleCollider).tag = f.wheel);
        break;

      case r.Basics_Items_Type.weapon:
        this.node_weapon.active = !0;
        var g = r.GetCarWeaponData(n.id),
            v = g.index;
        this.node_arrWeapon[v].active = !0, this.isHall || this.nAssemblyType == o.Assembly_Type.GameMatch || this.nAssemblyType == o.Assembly_Type.GameOver ? this.node_arrWeapon[v].anchorX = g.anchor.x : this.node_arrWeapon[v].setAnchorPoint(cc.v2(.5, .5)), this.node_arrWeapon[v].getComponent(cc.PolygonCollider) && (this.node_arrWeapon[v].getComponent(cc.PolygonCollider).tag = f.weapon), this.setStarQuality(this.frame_starLeveArr[n.quality]), this.scheduleOnce(function () {
          var t = s == o.Assembly_Type.Hall || s == o.Assembly_Type.SuperCar ? u.node_arrWeapon[v].width : 230,
              e = u.node_arrWeapon[v].width / u.node_arrWeapon[v].height;
          u.node_arrWeapon[v].width > t && (u.node_arrWeapon[v].width = t, u.node_arrWeapon[v].height = t / e);
        }, .1);
        break;

      case r.Basics_Items_Type.tools:
        this.node_tools.active = !0;
        var C = r.GetCarToolsData(n.id),
            b = C.index;
        this.node_arrTools[b].active = !0, this.isHall ? (this.node_arrTools[b].anchorX = C.anchor.x, this.node_arrTools[b].angle = C.rotation) : (this.node_arrTools[b].anchorX = .5, this.node_arrTools[b].angle = 0), this.node_arrTools[b].getComponent(cc.PolygonCollider) && (this.node_arrTools[b].getComponent(cc.PolygonCollider).tag = f.tools), this.scheduleOnce(function () {
          var t = u.node_arrTools[b].width / u.node_arrTools[b].height;
          u.node_arrTools[b].width > 150 && (u.node_arrTools[b].width = 150, u.node_arrTools[b].height = 150 / t);
        }, 1), this.setStarQuality(this.frame_starLeveArr[n.quality]);
    }

    this.recoverTouchMove();
  }, e.prototype.setBuffInfo = function (t) {
    t && (this.spr_explain.spriteFrame = this.frame_buffIcon[Number(t.buffType)], this.label_explain.string = "+" + Math.round(100 * (t.number - 1)) + "%");
  }, e.prototype.setArrow = function () {
    var t = cc.find("Canvas").getChildByName("car").getComponent(u["default"]).getCurAssemblyItem(this.itemData.type);
    t && t.itemData ? this.refreshArrowhead(t.itemData) : this.node_arrowhead.active = !1;
  }, e.prototype.onEventArrow = function (t) {
    this.itemData.type == r.Basics_Items_Type.wheel && (cc.log("收到:" + JSON.stringify(t)), this.refreshArrowhead(t));
  }, e.prototype.refreshArrowhead = function (t) {
    this.node_arrowhead.active = !0, h.Util.getOwnItemPower(t) < h.Util.getOwnItemPower(this.itemData) ? this.node_arrowhead.getChildByName("up").active = !0 : h.Util.getOwnItemPower(t) > h.Util.getOwnItemPower(this.itemData) ? this.node_arrowhead.getChildByName("up").active = !1 : this.node_arrowhead.active = !1, this.node_arrowhead.getChildByName("down").active = !this.node_arrowhead.getChildByName("up").active;
  }, e.prototype.getCarBody_Node = function () {}, e.prototype.getWeapon_Node = function () {
    return this.node_weapon;
  }, e.prototype.getTools_Node = function () {
    return this.node_tools;
  }, e.prototype.getWheel_Node = function () {
    return 255 == this.carWheelFrame0_control.node.opacity ? this.carWheelFrame0_control.node : 255 == this.carWheelFrame1_control.node.opacity ? this.carWheelFrame1_control.node : this.carWheelFrame0_control.node;
  }, e.prototype.setStarQuality = function (t) {
    for (var e = 0; e < 5; e++) {
      this.node_arrStar[e].getComponent(cc.Sprite).spriteFrame = t;
    }
  }, e.prototype.showEquipFrame = function (t, e, i, n) {
    if (t == o.Assembly_Type.GameMatch || t == o.Assembly_Type.GameOver) return this.carWeaponFrame0_control.node.active = !1, this.carToolsFrame0_control.node.active = !1, this.carWheelFrame0_control.node.active = !1, void (this.carWheelFrame1_control.node.active = !1);
    var a = r.GetCarBodyData(e);
    this.carWeaponFrame0_control.node.position = a.weaponPos[0], this.carToolsFrame0_control.node.position = a.toolsPos[0], this.carWheelFrame0_control.node.position = a.wheelPos[0], this.carWheelFrame1_control.node.position = a.wheelPos[1], this.isBodyMove || this.isHall ? this.node_car.scale = 1 : this.node_car.scale = a.assemblyScale, this.node_arrCar[i].getComponent(cc.PolygonCollider) ? (this.node_arrCar[i].getComponent(cc.PolygonCollider).tag = n, this.isBodyMove && (this.carWeaponFrame0_control.node.active = !1, this.carToolsFrame0_control.node.active = !1, this.carWheelFrame0_control.node.active = !1, this.carWheelFrame1_control.node.active = !1)) : (this.carWeaponFrame0_control.node.active = !1, this.carToolsFrame0_control.node.active = !1, this.carWheelFrame0_control.node.active = !1, this.carWheelFrame1_control.node.active = !1);
  }, e.prototype.showStar = function (t) {
    var e;
    e = t % 2 == 1 ? [cc.v3(0, 0, 0), cc.v3(40, 0, 0), cc.v3(-40, 0, 0), cc.v3(80, 0, 0), cc.v3(-80, 0, 0)] : [cc.v3(20, 0, 0), cc.v3(-20, 0, 0), cc.v3(60, 0, 0), cc.v3(-60, 0, 0)];

    for (var o = 0; o < this.node_arrStar.length; o++) {
      o < t ? (this.node_arrStar[o].active = !0, this.node_arrStar[o].position = e[o]) : this.node_arrStar[o].active = !1;
    }
  }, e.prototype.onActive = function (t) {
    this.node.active = t;
  }, e.prototype.onTouchStartCallback = function (t) {
    this.nAssemblyType != o.Assembly_Type.Assembly && this.nAssemblyType != o.Assembly_Type.Hall || (this.nAssemblyType == o.Assembly_Type.Hall && this.itemData && this.itemData.type == r.Basics_Items_Type.wheel && (cc.director.emit(p.arrow_message, this.itemData), cc.log("发送")), this.isPitchOnStart = !0, this._assemblyView && this._assemblyView.updateAttributeItem(this.itemData), t ? this.onLightActivie(!0) : this.onLightActivie(!1), this.isTouchEnable && (this._assemblyView.onTouchStart(this), this.setTouchState("start")));
  }, e.prototype.onTouchMoveCallback = function (t) {
    var e = this;
    if (this.isTouchEnable) if (this.setTouchState("move"), this.isHall) this.onTouchMoveHall(t);else {
      var o = t.getTouches()[0].getLocation(),
          i = this.node.convertToNodeSpaceAR(o);

      if (Math.abs(i.x) < this.node.width / 2 && (i.y < 0 && Math.abs(i.y) > this.node.height / 2 && !this.isTouchMove && (this.isTouchMove = !0, this._assemblyView.onTouchEnable(!0, this.nIndex, this.node.convertToWorldSpaceAR(i)), this.itemData && null != this.itemData.video && this.itemData.video && h.Util.showRewardVideo(function () {
        f["default"].show("获得奖励"), e.itemData.video = !1, e.node.getChildByName("icon_video").active = !1, e.node.getChildByName("icon_video_tt").active = !1, d["default"].saveTempCarData(e.itemData.type);
      }, function () {
        e.isTouchMove = !1, e._assemblyView.onTouchEnd(e.node.convertToWorldSpaceAR(cc.v2(0, 0)));
      }, function () {
        e.isTouchMove = !1, e._assemblyView.onTouchEnd(e.node.convertToWorldSpaceAR(cc.v2(0, 0)));
      })), i.y < -20 && !this.isTouchMove)) {
        Math.abs(i.y) > this.node.height / 2 && (this.isTouchMove = !0, this._assemblyView.onTouchEnable(!0, this.nIndex, this.node.convertToWorldSpaceAR(i)));
        var n = 1 - Math.abs(i.y + 20) / this.node.height;
        this.node_item.scale = 1 * n;
      }

      this._assemblyView.onTouchMoveCallback(t);
    }
  }, e.prototype.recoverTouchMove = function () {
    this.node_item.scale = 1, this.node_item.opacity = 255;
  }, e.prototype.onTouchEndCallback = function () {
    this.isPitchOnStart && this.onLightActivie(!0), this.isTouchEnable && (this.setTouchState("end"), this.isTouchMove ? (this.isTouchMove = !1, this._assemblyView.onTouchEnd(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))) : this.recoverTouchMove());
  }, e.prototype.onTouchCacelCallback = function () {
    this.isPitchOnStart = !1, this.isTouchEnable && (this.setTouchState("end"), this.isTouchMove ? (this.isTouchMove = !1, this._assemblyView.onTouchEnd(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))) : this.recoverTouchMove());
  }, e.prototype.onTouchMoveHall = function (t) {
    this.isTouchMove = !0;
    var e = t.getTouches()[0].getLocation(),
        o = this.node.parent.convertToNodeSpaceAR(e);
    this.node.position = o, "wheel" == this.itemData.type && this._assemblyView.onShowCarWheelFrame(!0);
  }, e.prototype.setTouchState = function (t) {
    this._assemblyView && this._assemblyView.setTouchState(t);
  }, e.prototype.getTouchState = function () {
    return this._assemblyView && this._assemblyView.getTouchState();
  }, e.prototype.getTouchMoveUid = function () {
    return this._assemblyView && this._assemblyView.getTouchMoveUid();
  }, e.prototype.getItemUid = function () {
    return this.itemDataUid;
  }, e.prototype.getItemPos = function () {
    return this.node.position;
  }, e.prototype.onEquipCarItem = function (t, e, o, i) {
    return this._assemblyView && this._assemblyView.onEquipCarItem(t, e, o, i);
  }, e.prototype.showCarWheelFrame = function (t, e) {
    this.carWheelFrame0_control.setOpacity(t[0] ? 255 : 0, e), this.carWheelFrame1_control.setOpacity(t[1] ? 255 : 0, e);
  }, e.prototype.showWeaponFrame = function (t, e) {
    this.carWeaponFrame0_control.setOpacity(t[0] ? 255 : 0, e);
  }, e.prototype.showToolsFrame = function (t, e) {
    this.carToolsFrame0_control.setOpacity(t[0] ? 255 : 0, e);
  }, e.prototype.setItemOpacity = function (t) {
    if (t) this.node.stopAllActions(), this.node.opacity = t;else {
      if (this.isTouchMove) return;
      cc.tween(this.node).to(.15, {
        opacity: 0
      }).start();
    }
  }, e.prototype.playAudio = function (t) {
    this._assemblyView.playAudio(t);
  }, e.prototype.onLightActivie = function (t, e) {
    if (t) {
      if (!e && this.isPitchOnEnd) return;
      this.isPitchOnStart && (cc.tween(this.node).to(.1, {
        scale: .8
      }).to(.2, {
        scale: 1.1
      }).to(.1, {
        scale: 1
      }).start(), this.isPitchOnStart = !1), this._assemblyView && this._assemblyView.onLightActivie(!1), this.node_light.active = !0, this._assemblyView && this._assemblyView.updateAttributeItem(this.itemData), this.node_light.getComponent(cc.Animation).play(), this.isPitchOnEnd = !0;
    } else this.isPitchOnStart = !1, this.isPitchOnEnd = !1, this.node_light.active = !1, this.node_light.getComponent(cc.Animation).stop();
  }, a([y(cc.Node)], e.prototype, "node_item", void 0), a([y(s["default"])], e.prototype, "carWheelFrame0_control", void 0), a([y(s["default"])], e.prototype, "carWheelFrame1_control", void 0), a([y(l["default"])], e.prototype, "carWeaponFrame0_control", void 0), a([y(c["default"])], e.prototype, "carToolsFrame0_control", void 0), a([y(cc.Node)], e.prototype, "node_null", void 0), a([y(cc.Node)], e.prototype, "node_car", void 0), a([y(cc.Node)], e.prototype, "node_wheel", void 0), a([y(cc.Node)], e.prototype, "node_weapon", void 0), a([y(cc.Node)], e.prototype, "node_tools", void 0), a([y(cc.Node)], e.prototype, "node_arrCar", void 0), a([y(cc.Node)], e.prototype, "node_arrWheel", void 0), a([y(cc.Node)], e.prototype, "node_arrWeapon", void 0), a([y(cc.Node)], e.prototype, "node_arrTools", void 0), a([y(cc.Node)], e.prototype, "node_star", void 0), a([y(cc.Node)], e.prototype, "node_arrStar", void 0), a([y([cc.SpriteFrame])], e.prototype, "frame_starLeveArr", void 0), a([y([cc.SpriteFrame])], e.prototype, "frame_buffIcon", void 0), a([y(cc.Sprite)], e.prototype, "spr_explain", void 0), a([y(cc.Label)], e.prototype, "label_explain", void 0), a([y(cc.Node)], e.prototype, "node_arrowhead", void 0), a([y(cc.Node)], e.prototype, "node_light", void 0), a([y([cc.SpriteFrame])], e.prototype, "carSpriteFrame1", void 0), a([y([cc.SpriteFrame])], e.prototype, "carSpriteFrame2", void 0), a([_], e);
}(cc.Component);

o.AssemblyItem = g;

cc._RF.pop();